package org.emmet.db4j.core.bean;

import org.emmet.db4j.core.util.DBUtil;

public class TableColumn {



    private String columnName;
    private String type;
    private boolean nullable;
    private String remarks;

    public TableColumn() {
    }

    public TableColumn(String columnName, String type, boolean nullable, String remarks) {
        this.columnName = columnName;
        this.type = type;
        this.nullable = nullable;
        this.remarks = remarks;
    }

    public String getColumnName() {
        if (DBUtil.SYSTEM_KEYWORD.toLowerCase().contains("," + columnName)) {
            return columnName + DBUtil.KEY_SUFFIX;
        } else {
            return columnName;
        }
    }

    public void setColumnName(String columnName) {
        this.columnName = columnName;
    }

    public String getType() {
        return type;
    }

    /**
     * 移除SQL中 UNSIGNED
     *
     * @return 字符串
     */
    public String getTypeFix() {
        return this.type.toUpperCase().replaceAll(" UNSIGNED", "");
    }

    public void setType(String type) {
        this.type = type;
    }

    public boolean isNullable() {
        return nullable;
    }

    public void setNullable(boolean nullable) {
        this.nullable = nullable;
    }

    public String getRemarks() {
        return remarks;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }

    @Override
    public String toString() {
        return "TableColumn{" +
                "columnName='" + columnName + '\'' +
                ", type='" + type + '\'' +
                ", nullable=" + nullable +
                '}';
    }
}
